import pytest
from selenium import webdriver

@pytest.fixture(scope="session")
def driver():
    driver = webdriver.Edge()
    url = "http://192.168.1.16/ecshop/user.php"
    driver.get(url=url)

    driver.get_screenshot_as_png()
    yield driver
    # 环境恢复
    driver.quit()


# 钩子函数，获取结果
@pytest.hookimpl(hookwrapper=True,tryfirst=True)
def pytest_runtest_makereport(item,call):
    # 获取钩子函数的结果
    out = yield
    # 获取测试报告
    report = out.get_result()
    # 脚本执行失败，截图
    # if report.when =='call' and report.outcome == "failed":